﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Tmp.Models;

public class Language
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long LanguageId { get; set; }

    public string? Lang { get; set; }

    public string? Highlight { get; set; }

    public ICollection<SharedCode> SharedCodes { get; set; }

    private static IEnumerable<Language>? _innerLanguage;

    public static Language? FindLanguageByHighLight(string? highlight)
    {
        if (_innerLanguage == null)
        {
            All();
        }
        if (highlight is null or "")
        {
            return new Language()
            {
                Lang = "auto",
                Highlight = ""
            };
        }
        var language = _innerLanguage?.FirstOrDefault(lang => lang.Highlight == highlight);

        return language;
    }
    public static IEnumerable<Language> All()
    {
        if (_innerLanguage != null)
        {
            return _innerLanguage;
        }
        var languages = new List<Language>()
        {
            new Language { Lang = "Python", Highlight = "language-python" },
            new Language { Lang = "JavaScript", Highlight = "language-javascript" },
            new Language { Lang = "Java", Highlight = "language-java" },
            new Language { Lang = "C#", Highlight = "language-csharp" },
            new Language { Lang = "C++", Highlight = "language-cpp" },
            new Language { Lang = "Ruby", Highlight = "language-ruby" },
            new Language { Lang = "Swift", Highlight = "language-swift" },
            new Language { Lang = "Go", Highlight = "language-go" },
            new Language { Lang = "Kotlin", Highlight = "language-kotlin" },
            new Language { Lang = "TypeScript", Highlight = "language-typescript" },
            new Language { Lang = "PHP", Highlight = "language-php" },
            new Language { Lang = "Rust", Highlight = "language-rust" },
            new Language { Lang = "MATLAB", Highlight = "language-matlab" },
            new Language { Lang = "R", Highlight = "language-r" },
            new Language { Lang = "Objective-C", Highlight = "language-objectivec" },
            new Language { Lang = "Perl", Highlight = "language-perl" },
            new Language { Lang = "Lua", Highlight = "language-lua" },
            new Language { Lang = "Shell", Highlight = "language-shell" },
            new Language { Lang = "Scala", Highlight = "language-scala" },
            new Language { Lang = "Groovy", Highlight = "language-groovy" },
            new Language { Lang = "Dart", Highlight = "language-dart" },
            new Language { Lang = "Julia", Highlight = "language-julia" },
            new Language { Lang = "Haskell", Highlight = "language-haskell" },
            new Language { Lang = "PowerShell", Highlight = "language-powershell" },
            new Language { Lang = "VBA (Visual Basic for Applications)", Highlight = "language-vba" },
            new Language { Lang = "HTML/CSS", Highlight = "language-html" },
            new Language { Lang = "SQL", Highlight = "language-sql" },
            new Language { Lang = "Assembly language", Highlight = "language-asm" },
            new Language { Lang = "Fortran", Highlight = "language-fortran" },
            new Language { Lang = "Cobol", Highlight = "language-cobol" },
            new()
            {
                Lang = "auto",
                Highlight = null
            }
        };

        _innerLanguage = languages;
        return languages;
    }
}
